import 'dart:ffi';

import 'package:flutter/material.dart';



class xSpring extends StatefulWidget{
  Widget child;
  double state;

  xSpring({
    required this.child,
    required this.state,
  });

  @override
  _textLuminescence createState(){
    return new _textLuminescence();
  }
}


class _textLuminescence  extends State<xSpring> with SingleTickerProviderStateMixin {


  _textLuminescence();

  late Animation<double> animation;
  late AnimationController controller;

  @override
  void initState() {
    super.initState();
    controller = AnimationController(duration: const Duration(milliseconds: 300), vsync: this);
    animation = CurvedAnimation(parent: controller, curve: Curves.easeInBack)..addStatusListener((status) {
      // if (status == AnimationStatus.completed) {
      //   controller.reverse();
      // } else if (status == AnimationStatus.dismissed) {
      //   controller.forward();
      // }
    });
    //controller.forward();
  }

  Widget build(BuildContext context) {

    if(widget.state == 1){
      (controller as AnimationController).forward();
    }

    if(widget.state == 2){
      (controller as AnimationController).reverse();
    }

    return Container(
      child: AnimatedLogo(animation: animation,child:widget.child,state:widget.state),
    );
  }
}

class AnimatedLogo extends AnimatedWidget {
  Widget child;
  double state;

  AnimatedLogo({super.key, required Animation<double> animation,required this.child,required this.state})
      : super(listenable: animation);

  // Make the Tweens static because they don't change.

  static final _blurRadiusTween = Tween<double>(begin: 0, end:-6);

  @override
  Widget build(BuildContext context) {
    final animation = listenable as Animation<double>;



    return Center(
      child: Container(
        child:Align(
          alignment: Alignment( _blurRadiusTween.evaluate(animation),0),
          child: child,
        )
      )
    );
  }
}